﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Serialization;

namespace Arbalest.Web.Models
{
    [Serializable]
    [XmlRoot("MenuItem")]
    public class MenuItem
    {
        [XmlAttribute("displayName")]
        public string DisplayName {get;set;}
        
        [XmlAttribute("url")]
        public string Url {get;set;}
        
        [XmlAttribute("tooltipText")]
        public string TooltipText { get; set; }

        [XmlElement("MenuItems")]
        List<MenuItem> ChildMenuItems { get; set; }

        public MenuItem()
        {
            this.DisplayName = string.Empty;
            this.Url = string.Empty;
            this.TooltipText = string.Empty;
            this.ChildMenuItems = new List<MenuItem>();
        }

        public static void Run()
        {
            MenuItem mi = new MenuItem()
            {
                DisplayName = "Home",
                Url="~/",
                TooltipText="Home tooltip"
            };

            mi.ChildMenuItems.Add(
                new MenuItem()
                {
                    DisplayName = "Child 1",
                    Url = "~/Child1",
                    TooltipText = "Child1 tooltip"
                });
            mi.ChildMenuItems.Add(
                new MenuItem()
                {
                    DisplayName = "Child 2",
                    Url = "~/Child2",
                    TooltipText = "Child2 tooltip"
                });


            XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
            ns.Add(string.Empty, string.Empty);

            XmlSerializer s = new XmlSerializer(typeof(MenuItem));
            System.IO.StreamWriter sw = new System.IO.StreamWriter("C:\\temp\\test.xml");
            sw.AutoFlush = true;
            s.Serialize(sw, mi, ns);

            
        }
    }

    
}